//
//  ResolveErrorViewController.m
//  Tools
//
//  Created by zhangqianchu on 2018/6/3.
//  Copyright © 2018年 zhangqianchu. All rights reserved.
//

#import "ResolveErrorViewController.h"

@interface ResolveErrorViewController ()

@end

@implementation ResolveErrorViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do view setup here.
    self.title = @"QTools";
}

- (IBAction)resolveError:(id)sender {
    NSString *mapping = _mappingPath.stringValue;
    NSString *error = _errorPath.stringValue;
    
    _resolveError([mapping cStringUsingEncoding:NSASCIIStringEncoding], [error cStringUsingEncoding:NSASCIIStringEncoding]);
}


- (IBAction)installApp:(id)sender {
//    printf("installApp/n");
    NSString *str = _mappingPath.stringValue;
    printf("installApp %s", [str cStringUsingEncoding:NSASCIIStringEncoding]);
    char buf[0] = {0};
    uint32_t size = 0;
    _NSGetExecutablePath(buf,&size);
    char* path = (char*)malloc(size+1 + 5);
    path[size] = 0;
    _NSGetExecutablePath(path,&size);
    strcat(path, "/adb ");
    //printf("%s",path);
    NSString *resources = NSBundle.mainBundle.resourcePath;
    NSString *adb = @"/adb ";
    NSString *result = [resources stringByAppendingString:adb];
    
    NSString *home = NSHomeDirectory();
//    printf([result UTF8String]);
    _install([home UTF8String], [str cStringUsingEncoding:NSASCIIStringEncoding]);
    
}

@end
